import { request } from '@/api/request';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import type { YmColumnsType } from 'ym-design';
import { YmTable } from 'ym-design';
type RecordType = {
  safetyIndexDriverId: string;
  driverName: string;
  driverPhone: string;
  safetyIndex: number;
  verifiedStatus: number;
  drivingLicenseStatus: number;
  createTime: string;
  driverId: string;
};
const DriverList = ({ entId }: { entId: string }) => {
  const navigator = useNavigate();
  const [columns] = useState<YmColumnsType<RecordType>>([
    {
      title: '司机姓名',
      dataIndex: 'driverName',
      ellipsis: true,
      key: 'packageName',
      render(value, record, index) {
        return (
          <span
            className="safe-edu_table_operation_text"
            onClick={() => {
              navigator(
                `/safeIndex/safeIndexStatistics/driverIndexInfo?entId=${entId}&driverName=${value}&driverId=${record.driverId}`,
              );
            }}
          >
            {value}
          </span>
        );
      },
    },
    {
      title: '司机手机号',
      dataIndex: 'driverPhone',
      key: 'driverPhone',
    },
    {
      title: '司机安全指数',
      dataIndex: 'safetyIndex',
      ellipsis: true,
      key: 'safetyIndex',
    },
    {
      title: '实名',
      dataIndex: 'verifiedStatus',
      ellipsis: true,
      key: 'verifiedStatus',
      render: (text, record) => <span>{text == 1 ? '审核中' : text == 2 ? '已认证' : '未认证'}</span>,
    },
    {
      title: '驾驶证',
      dataIndex: 'drivingLicenseStatus',
      key: 'drivingLicenseStatus',
      ellipsis: true,
      render: (text, record) => <span>{text == 1 ? '审核中' : text == 2 ? '已认证' : '未认证'}</span>,
    },
    {
      title: '注册时间',
      dataIndex: 'createTime',
      ellipsis: true,
      key: 'createTime',
    },
  ]);
  const [tableDep, _reFreshTable] = useState<number>();

  return (
    <YmTable
      style={{ minHeight: '600px ' }}
      wrapperStyle={{ padding: 0 }}
      columns={columns}
      request={async ({ page }, form) => {
        const { data } = await request<{ list: any[]; total: number }>({
          url: '/unicron/ent/safetyIndex/entDriverList',
          data: {
            entId,
            ...page,
          },
        });
        return data;
      }}
      requestOptions={{
        reFreshDep: [tableDep],
        defaultPageSize: 10,
      }}
      rowKey="safetyIndexDriverId"
    />
  );
};
export default DriverList;
